import { Module } from '@nestjs/common';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { join, resolve } from 'path';
import { GrpcService } from './grpc.service';
import { CODE_PACKAGE_NAME, CODE_SERVICE_NAME } from './code';

@Module({
  imports: [
    ClientsModule.register([
      {
        name: CODE_SERVICE_NAME,
        transport: Transport.GRPC,
        options: {
          package: CODE_PACKAGE_NAME,
          protoPath: join(resolve('../'), 'go/common/protos/code.proto'),
          url: 'localhost:28375',
          loader: { defaults: true },
        },
      },
    ]),
  ],
  providers: [GrpcService],
  exports: [GrpcService],
})
export class GrpcModule {}
